using System;
using System.Collections.Generic;
using System.Text;
using QLPMT_DTO;
using QLPMT_DAO;

namespace QLPMT_BUS
{
   public class PhieuKhamBUS
    {
       // Lay Ma Phieu Kham
       public string GetMaPhieuKham()
       {

           List<PhieuKham> list = new List<PhieuKham>();
           list = new PhieuKhamDAO().DanhSachPhieuKham();
           PhieuKham temp = new PhieuKham();
           foreach(PhieuKham X in list)
           {
               temp.Maphieukham = X.Maphieukham;
           }
           string ma="";
           if (temp.Maphieukham!=null)
           {
               char[] chuoi = temp.Maphieukham.ToCharArray(2, temp.Maphieukham.Length - 2);
               string chuoima = "";
               foreach (char charX in chuoi)
               {
                   chuoima = chuoima + charX;
               }
               int sobenhnhan = int.Parse(chuoima) + 1;
                ma = "PK" + sobenhnhan.ToString();
           }
           else
                ma="PK1";
           return ma;
       }
       //Them 1 phieu kham 
       public Boolean InsertPhieuKham(string ma,string makhambenh,string trieuchung)
       {
           try
           {
               PhieuKham dto = new PhieuKham(ma, makhambenh, trieuchung);
               new PhieuKhamDAO().InsertPhieuKham(dto);
           }
           catch
           {
               return false;
           }
           return true;
       }
       // Danh sach phieu kham theo ngay kham
       public List<PhieuKham> DanhSachPhieuKhamCungNGay(DateTime ngay)
       {
           List<PhieuKham> list = new List<PhieuKham>();
           list = new PhieuKhamDAO().DanhSachPhieuKhamCungNgay(ngay);
           return list;
       }
    }
}
